﻿using EFCore.Models;
using Microsoft.EntityFrameworkCore;
using SIService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SService
{
    public class SalesorderdetailS : SalesorderdetailSI
    {
        private readonly WmssystemContext myDb;

        public SalesorderdetailS(WmssystemContext myDb)
        {
            this.myDb = myDb;
        }

        public async Task<int> Add(PO_Salesorderdetail pO_Salesorderdetail)
        {
            myDb.PO_Salesorderdetail.Add(pO_Salesorderdetail); // 确保不显式指定标识列的值
            return await myDb.SaveChangesAsync();
        }

        public async Task<List<PO_Salesorderdetail>> Qu(string dh)
        {
            //return myDb.PO_Salesorderdetail.ToListAsync();
            //return myDb.PO_Salesorderdetail.OrderByDescending(p => p.S_DSerialNumber).ToListAsync();
            var result = await myDb.PO_Salesorderdetail
    .Where(p => p.S_DSaCode == dh)  // 根据条件过滤结果
    .OrderByDescending(p => p.S_DSerialNumber)  // 根据 P_DSerialNumber 排序
    .ToListAsync();  // 转换为列表

            return result;
        }
    }
}
